package org.spring.boot.sample.hystrix.controller;

import java.io.InputStream;
import java.net.URL;

import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.spring.boot.sample.hystrix.command.http.SmsSendCommand;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SmsController {
	
	@RequestMapping(value = "/sms/send", method = RequestMethod.GET)
	public String sendSms() throws Exception{
		URL url = new URL("http://127.0.0.1:8000/sms/15823345333");
		byte[] result = new byte[8];
		InputStream input = url.openStream();
		IOUtils.readFully(input, result);
		String msg = new String(result);
		System.out.println("收到短信网关结果: " + msg);
		return msg;
	}
	
	@RequestMapping(value = "/sms/hystrix", method = RequestMethod.GET)
	public String sendSmsByhystrix() throws InterruptedException{
		String msg = new SmsSendCommand().execute();
		System.out.println("收到短信网关结果: " + msg);
		return msg;
	}
}
